Shuttle - Deploy Rust apps with a single Cargo subcommand
Hello, and welcome to the shuttle API documentation!
Shuttle is an open-source app platform that uses traits and annotations to configure your backend deployments.
Usage
Start by installing the cargo shuttle
subcommand by running the following in a terminal:
Now that shuttle is installed, you can initialize a project with Rocket boilerplate:
By looking at the Cargo.toml
file of the generated my-rocket-app
project you will see it has been made to
be a library crate with a shuttle-service
dependency with the web-rocket
feature on the shuttle-service
dependency.
= { = "0.7.2", = ["web-rocket"] }
A boilerplate code for your rocket project can also be found in src/lib.rs
:
extern crate rocket;
use ShuttleRocket;
async
See the [shuttle_service::main][main] macro for more information on supported services - such as axum
.
Or look at more complete examples in the repository, but
take note that the examples may update before official releases.
Running locally
To test your app locally before deploying, use:
You should see your app build and start on the default port 8000. You can test this using;
Deploying
You can deploy your service with the cargo shuttle
subcommand too.
But, you will need to authenticate with the shuttle service first using:
this will open a browser window and prompt you to connect using your GitHub account.
Before you can deploy, you have to create a project. This will start a deployer container for your project under the hood, ensuring isolation from other users' projects.
Then, deploy the service with:
Your service will immediately be available at {crate_name}.shuttleapp.rs
. For example:
Using sqlx
Here is a quick example to deploy a service that uses a postgres database and sqlx:
Add shuttle-shared-db
as a dependency with the postgres
feature, and add sqlx
as a dependency with the runtime-tokio-native-tls
and postgres
features inside Cargo.toml
:
= { = "0.7.2", = ["postgres"] }
= { = "0.6.1", = ["runtime-tokio-native-tls", "postgres"] }
Now update the #[shuttle_service::main]
function to take in a PgPool
:
extern crate rocket;
use State;
use PgPool;
use ShuttleRocket;
;
async
For a local run, shuttle will automatically provision a Postgres instance inside a Docker container on your machine and connect it to the PgPool
.
For deploys, shuttle will provision a database for your application and connect it to the PgPool
on your behalf.
To learn more about shuttle managed resources, see [shuttle_service::main][main#getting-shuttle-managed-resources].
Configuration
The cargo shuttle
command can be customised by creating a Shuttle.toml
in the same location as your Cargo.toml
.
Change the name of your service
To have your service deployed with a different name, add a name
entry in the Shuttle.toml
:
= "hello-world"
If the name
key is not specified, the service's name will be the same as the crate's name.
Alternatively, you can override the project name on the command-line, by passing the --name argument to any subcommand like so:
Using Podman instead of Docker
If you are using Podman instead of Docker, then cargo shuttle run
will give
got unexpected error while inspecting docker container: error trying to connect: No such file or directory
error.
To fix this error you will need to expose a rootless socket for Podman first. This can be done using:
Now set the DOCKER_HOST
environment variable to point to this socket using:
Now all cargo shuttle run
commands will work against Podman.
Getting API keys
After you've installed the cargo-shuttle command, run:
this will open a browser window and prompt you to connect using your GitHub account.
We're in alpha 🤗
Thanks for using shuttle! We're very happy to have you with us!
During our alpha period, API keys are completely free and you can deploy as many services as you want.
Just keep in mind that there may be some kinks that require us to take all deployments down once in a while. In certain circumstances we may also have to delete all the data associated with those deployments.
To stay updated with the release status of shuttle, join our Discord!
Join Discord
If you have any questions, join our Discord server. There's always someone on there that can help!
You can also open an issue or a discussion on GitHub.